package com.ss.android.lockscreen;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.support.v4.util.ArrayMap;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public final class aa {
    public static boolean a;
    private static Map b;
    private static JSONArray c;

    static {
        a = false;
        b = Collections.synchronizedMap(new ArrayMap());
        c = null;
    }

    public static Map a() {
        if(b.size() <= 0) {
            b.put("com.ss.android.article.news", Integer.valueOf(1000));
            b.put("com.ss.android.article.local", Integer.valueOf(999));
            b.put("com.ss.android.article.lite", Integer.valueOf(990));
            b.put("com.ss.android.article.video", Integer.valueOf(980));
            b.put("com.ss.android.ugc.live", Integer.valueOf(970));
            b.put("com.ss.android.essay.joke", Integer.valueOf(960));
            b.put("com.ss.android.ugc.aweme", Integer.valueOf(950));
            b.put("com.ss.android.article.wenda", Integer.valueOf(940));
            b.put("com.ss.android.article.shell", Integer.valueOf(930));
            b.put("com.ss.android.article.cover", Integer.valueOf(920));
            b.put("com.ss.android.auto", Integer.valueOf(910));
            b.put("tc.everphoto", Integer.valueOf(900));
            b.put("com.ss.android.article.topbuzzvideo", Integer.valueOf(890));
            b.put("com.ss.android.article.master", Integer.valueOf(880));
            b.put("com.ss.android.article.mynews.br", Integer.valueOf(870));
            b.put("com.ss.android.article.topbuzzlite", Integer.valueOf(860));
            b.put("com.ss.android.article.topbuzzvideo.en", Integer.valueOf(850));
            b.put("com.ss.android.article.topbuzzvideo.general", Integer.valueOf(840));
            b.put("id.co.babe", Integer.valueOf(830));
            b.put("com.ss.android.article.master.id", Integer.valueOf(820));
            b.put("com.ss.android.article.topbuzzvideo.id", Integer.valueOf(810));
            b.put("com.ss.android.article.topbuzzvideo.india", Integer.valueOf(800));
            b.put("com.ss.android.article.topbuzzlite.en", Integer.valueOf(790));
            b.put("com.ss.android.ugc.trill", Integer.valueOf(780));
            b.put("com.ss.android.article.browser", Integer.valueOf(770));
            b.put("com.ss.android.camera", Integer.valueOf(760));
            d();
        }

        return b;
    }

    public static void a(Map arg0) {
        b = arg0;
        d();
    }

    public static JSONArray b() {
        if(c == null) {
            d();
        }

        return c;
    }

    public static JSONArray c() {
        JSONArray v0 = new JSONArray();
        Context v1 = com.ss.android.lockscreen.bb.a().a;
        if(v1 != null) {
            try {
                PackageInfo v1_3 = v1.getPackageManager().getPackageInfo(v1.getPackageName(), 0);
                JSONObject v2 = new JSONObject();
                v2.put("package", v1_3.packageName);
                v2.put("version_code", v1_3.versionCode);
                v0.put(v2);
            }
            catch(JSONException v1_1) {
                v1_1.printStackTrace();
            }
            catch(PackageManager.NameNotFoundException v1_2) {
                v1_2.printStackTrace();
            }
        }

        return v0;
    }

    private static void d() {
        Context v1 = bb.a().a;
        if(v1 != null) {
            c = new JSONArray();
            Iterator v2 = a().keySet().iterator();
            while(v2.hasNext()) {
                Object v0 = v2.next();
                if(v0 == null) {
                    continue;
                }

                try {
                    PackageInfo v0_3 = v1.getPackageManager().getPackageInfo(((String)v0), 256);
                    if(v0_3 == null) {
                        continue;
                    }

                    Intent v3 = new Intent();
                    v3.setClassName(v0_3.packageName, "com.ss.android.lockscreen.component.TmpActivity");
                    if(v1.getPackageManager().resolveActivity(v3, 0) == null) {
                        continue;
                    }

                    JSONObject v3_1 = new JSONObject();
                    v3_1.put("package", v0_3.packageName);
                    v3_1.put("version_code", v0_3.versionCode);
                    c.put(v3_1);
                }
                catch(JSONException v0_1) {
                    v0_1.printStackTrace();
                }
                catch(PackageManager.NameNotFoundException v0_2) {
                }
            }
        }
    }
}

